package snapex.core.mapper;

import static org.mybatis.dynamic.sql.SqlBuilder.*;
import static snapex.core.mapper.ExpenseDynamicSqlSupport.*;

import java.util.List;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.SqlBuilder;
import org.mybatis.dynamic.sql.delete.DeleteDSL;
import org.mybatis.dynamic.sql.delete.MyBatis3DeleteModelAdapter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.render.RenderingStrategy;
import org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter;
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
import org.mybatis.dynamic.sql.select.SelectDSL;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.MyBatis3UpdateModelAdapter;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import snapex.core.model.Expense;

@Mapper
public interface ExpenseMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<Expense> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("ExpenseResult")
    Expense selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="ExpenseResult", value = {
        @Result(column="expense_id", property="expenseId", jdbcType=JdbcType.CHAR, id=true),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
        @Result(column="next_approver", property="nextApprover", jdbcType=JdbcType.VARCHAR),
        @Result(column="last_approver", property="lastApprover", jdbcType=JdbcType.VARCHAR),
        @Result(column="staff_id", property="staffId", jdbcType=JdbcType.VARCHAR),
        @Result(column="extension_no", property="extensionNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="site_id", property="siteId", jdbcType=JdbcType.INTEGER),
        @Result(column="total_amount", property="totalAmount", jdbcType=JdbcType.DECIMAL),
        @Result(column="expense_cash_advance_amount", property="expenseCashAdvanceAmount", jdbcType=JdbcType.DECIMAL),
        @Result(column="submitted_date", property="submittedDate", jdbcType=JdbcType.DATE),
        @Result(column="confirmed_date", property="confirmedDate", jdbcType=JdbcType.DATE),
        @Result(column="clarity_project_id", property="clarityProjectId", jdbcType=JdbcType.VARCHAR),
        @Result(column="clarity_project_name", property="clarityProjectName", jdbcType=JdbcType.VARCHAR),
        @Result(column="customer_cost_centre_name", property="customerCostCentreName", jdbcType=JdbcType.VARCHAR),
        @Result(column="customer_cost_centre_no", property="customerCostCentreNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="billable", property="billable", jdbcType=JdbcType.INTEGER),
        @Result(column="customer_cost_centre_mandatory", property="customerCostCentreMandatory", jdbcType=JdbcType.VARCHAR),
        @Result(column="username", property="username", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_timestamp", property="createTimestamp", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="sync_timestamp", property="syncTimestamp", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Expense> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<Long>> countByExample() {
        return SelectDSL.selectWithMapper(this::count, SqlBuilder.count())
                .from(expense);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default DeleteDSL<MyBatis3DeleteModelAdapter<Integer>> deleteByExample() {
        return DeleteDSL.deleteFromWithMapper(this::delete, expense);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(String expenseId_) {
        return DeleteDSL.deleteFromWithMapper(this::delete, expense)
                .where(expenseId, isEqualTo(expenseId_))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(Expense record) {
        return insert(SqlBuilder.insert(record)
                .into(expense)
                .map(expenseId).toProperty("expenseId")
                .map(status).toProperty("status")
                .map(nextApprover).toProperty("nextApprover")
                .map(lastApprover).toProperty("lastApprover")
                .map(staffId).toProperty("staffId")
                .map(extensionNo).toProperty("extensionNo")
                .map(siteId).toProperty("siteId")
                .map(totalAmount).toProperty("totalAmount")
                .map(expenseCashAdvanceAmount).toProperty("expenseCashAdvanceAmount")
                .map(submittedDate).toProperty("submittedDate")
                .map(confirmedDate).toProperty("confirmedDate")
                .map(clarityProjectId).toProperty("clarityProjectId")
                .map(clarityProjectName).toProperty("clarityProjectName")
                .map(customerCostCentreName).toProperty("customerCostCentreName")
                .map(customerCostCentreNo).toProperty("customerCostCentreNo")
                .map(billable).toProperty("billable")
                .map(customerCostCentreMandatory).toProperty("customerCostCentreMandatory")
                .map(username).toProperty("username")
                .map(description).toProperty("description")
                .map(createTimestamp).toProperty("createTimestamp")
                .map(syncTimestamp).toProperty("syncTimestamp")
                .build()
                .render(RenderingStrategy.MYBATIS3));
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(Expense record) {
        return insert(SqlBuilder.insert(record)
                .into(expense)
                .map(expenseId).toPropertyWhenPresent("expenseId", record::getExpenseId)
                .map(status).toPropertyWhenPresent("status", record::getStatus)
                .map(nextApprover).toPropertyWhenPresent("nextApprover", record::getNextApprover)
                .map(lastApprover).toPropertyWhenPresent("lastApprover", record::getLastApprover)
                .map(staffId).toPropertyWhenPresent("staffId", record::getStaffId)
                .map(extensionNo).toPropertyWhenPresent("extensionNo", record::getExtensionNo)
                .map(siteId).toPropertyWhenPresent("siteId", record::getSiteId)
                .map(totalAmount).toPropertyWhenPresent("totalAmount", record::getTotalAmount)
                .map(expenseCashAdvanceAmount).toPropertyWhenPresent("expenseCashAdvanceAmount", record::getExpenseCashAdvanceAmount)
                .map(submittedDate).toPropertyWhenPresent("submittedDate", record::getSubmittedDate)
                .map(confirmedDate).toPropertyWhenPresent("confirmedDate", record::getConfirmedDate)
                .map(clarityProjectId).toPropertyWhenPresent("clarityProjectId", record::getClarityProjectId)
                .map(clarityProjectName).toPropertyWhenPresent("clarityProjectName", record::getClarityProjectName)
                .map(customerCostCentreName).toPropertyWhenPresent("customerCostCentreName", record::getCustomerCostCentreName)
                .map(customerCostCentreNo).toPropertyWhenPresent("customerCostCentreNo", record::getCustomerCostCentreNo)
                .map(billable).toPropertyWhenPresent("billable", record::getBillable)
                .map(customerCostCentreMandatory).toPropertyWhenPresent("customerCostCentreMandatory", record::getCustomerCostCentreMandatory)
                .map(username).toPropertyWhenPresent("username", record::getUsername)
                .map(description).toPropertyWhenPresent("description", record::getDescription)
                .map(createTimestamp).toPropertyWhenPresent("createTimestamp", record::getCreateTimestamp)
                .map(syncTimestamp).toPropertyWhenPresent("syncTimestamp", record::getSyncTimestamp)
                .build()
                .render(RenderingStrategy.MYBATIS3));
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<Expense>>> selectByExample() {
        return SelectDSL.selectWithMapper(this::selectMany, expenseId, status, nextApprover, lastApprover, staffId, extensionNo, siteId, totalAmount, expenseCashAdvanceAmount, submittedDate, confirmedDate, clarityProjectId, clarityProjectName, customerCostCentreName, customerCostCentreNo, billable, customerCostCentreMandatory, username, description, createTimestamp, syncTimestamp)
                .from(expense);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<Expense>>> selectDistinctByExample() {
        return SelectDSL.selectDistinctWithMapper(this::selectMany, expenseId, status, nextApprover, lastApprover, staffId, extensionNo, siteId, totalAmount, expenseCashAdvanceAmount, submittedDate, confirmedDate, clarityProjectId, clarityProjectName, customerCostCentreName, customerCostCentreNo, billable, customerCostCentreMandatory, username, description, createTimestamp, syncTimestamp)
                .from(expense);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Expense selectByPrimaryKey(String expenseId_) {
        return SelectDSL.selectWithMapper(this::selectOne, expenseId, status, nextApprover, lastApprover, staffId, extensionNo, siteId, totalAmount, expenseCashAdvanceAmount, submittedDate, confirmedDate, clarityProjectId, clarityProjectName, customerCostCentreName, customerCostCentreNo, billable, customerCostCentreMandatory, username, description, createTimestamp, syncTimestamp)
                .from(expense)
                .where(expenseId, isEqualTo(expenseId_))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExample(Expense record) {
        return UpdateDSL.updateWithMapper(this::update, expense)
                .set(expenseId).equalTo(record::getExpenseId)
                .set(status).equalTo(record::getStatus)
                .set(nextApprover).equalTo(record::getNextApprover)
                .set(lastApprover).equalTo(record::getLastApprover)
                .set(staffId).equalTo(record::getStaffId)
                .set(extensionNo).equalTo(record::getExtensionNo)
                .set(siteId).equalTo(record::getSiteId)
                .set(totalAmount).equalTo(record::getTotalAmount)
                .set(expenseCashAdvanceAmount).equalTo(record::getExpenseCashAdvanceAmount)
                .set(submittedDate).equalTo(record::getSubmittedDate)
                .set(confirmedDate).equalTo(record::getConfirmedDate)
                .set(clarityProjectId).equalTo(record::getClarityProjectId)
                .set(clarityProjectName).equalTo(record::getClarityProjectName)
                .set(customerCostCentreName).equalTo(record::getCustomerCostCentreName)
                .set(customerCostCentreNo).equalTo(record::getCustomerCostCentreNo)
                .set(billable).equalTo(record::getBillable)
                .set(customerCostCentreMandatory).equalTo(record::getCustomerCostCentreMandatory)
                .set(username).equalTo(record::getUsername)
                .set(description).equalTo(record::getDescription)
                .set(createTimestamp).equalTo(record::getCreateTimestamp)
                .set(syncTimestamp).equalTo(record::getSyncTimestamp);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExampleSelective(Expense record) {
        return UpdateDSL.updateWithMapper(this::update, expense)
                .set(expenseId).equalToWhenPresent(record::getExpenseId)
                .set(status).equalToWhenPresent(record::getStatus)
                .set(nextApprover).equalToWhenPresent(record::getNextApprover)
                .set(lastApprover).equalToWhenPresent(record::getLastApprover)
                .set(staffId).equalToWhenPresent(record::getStaffId)
                .set(extensionNo).equalToWhenPresent(record::getExtensionNo)
                .set(siteId).equalToWhenPresent(record::getSiteId)
                .set(totalAmount).equalToWhenPresent(record::getTotalAmount)
                .set(expenseCashAdvanceAmount).equalToWhenPresent(record::getExpenseCashAdvanceAmount)
                .set(submittedDate).equalToWhenPresent(record::getSubmittedDate)
                .set(confirmedDate).equalToWhenPresent(record::getConfirmedDate)
                .set(clarityProjectId).equalToWhenPresent(record::getClarityProjectId)
                .set(clarityProjectName).equalToWhenPresent(record::getClarityProjectName)
                .set(customerCostCentreName).equalToWhenPresent(record::getCustomerCostCentreName)
                .set(customerCostCentreNo).equalToWhenPresent(record::getCustomerCostCentreNo)
                .set(billable).equalToWhenPresent(record::getBillable)
                .set(customerCostCentreMandatory).equalToWhenPresent(record::getCustomerCostCentreMandatory)
                .set(username).equalToWhenPresent(record::getUsername)
                .set(description).equalToWhenPresent(record::getDescription)
                .set(createTimestamp).equalToWhenPresent(record::getCreateTimestamp)
                .set(syncTimestamp).equalToWhenPresent(record::getSyncTimestamp);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(Expense record) {
        return UpdateDSL.updateWithMapper(this::update, expense)
                .set(status).equalTo(record::getStatus)
                .set(nextApprover).equalTo(record::getNextApprover)
                .set(lastApprover).equalTo(record::getLastApprover)
                .set(staffId).equalTo(record::getStaffId)
                .set(extensionNo).equalTo(record::getExtensionNo)
                .set(siteId).equalTo(record::getSiteId)
                .set(totalAmount).equalTo(record::getTotalAmount)
                .set(expenseCashAdvanceAmount).equalTo(record::getExpenseCashAdvanceAmount)
                .set(submittedDate).equalTo(record::getSubmittedDate)
                .set(confirmedDate).equalTo(record::getConfirmedDate)
                .set(clarityProjectId).equalTo(record::getClarityProjectId)
                .set(clarityProjectName).equalTo(record::getClarityProjectName)
                .set(customerCostCentreName).equalTo(record::getCustomerCostCentreName)
                .set(customerCostCentreNo).equalTo(record::getCustomerCostCentreNo)
                .set(billable).equalTo(record::getBillable)
                .set(customerCostCentreMandatory).equalTo(record::getCustomerCostCentreMandatory)
                .set(username).equalTo(record::getUsername)
                .set(description).equalTo(record::getDescription)
                .set(createTimestamp).equalTo(record::getCreateTimestamp)
                .set(syncTimestamp).equalTo(record::getSyncTimestamp)
                .where(expenseId, isEqualTo(record::getExpenseId))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(Expense record) {
        return UpdateDSL.updateWithMapper(this::update, expense)
                .set(status).equalToWhenPresent(record::getStatus)
                .set(nextApprover).equalToWhenPresent(record::getNextApprover)
                .set(lastApprover).equalToWhenPresent(record::getLastApprover)
                .set(staffId).equalToWhenPresent(record::getStaffId)
                .set(extensionNo).equalToWhenPresent(record::getExtensionNo)
                .set(siteId).equalToWhenPresent(record::getSiteId)
                .set(totalAmount).equalToWhenPresent(record::getTotalAmount)
                .set(expenseCashAdvanceAmount).equalToWhenPresent(record::getExpenseCashAdvanceAmount)
                .set(submittedDate).equalToWhenPresent(record::getSubmittedDate)
                .set(confirmedDate).equalToWhenPresent(record::getConfirmedDate)
                .set(clarityProjectId).equalToWhenPresent(record::getClarityProjectId)
                .set(clarityProjectName).equalToWhenPresent(record::getClarityProjectName)
                .set(customerCostCentreName).equalToWhenPresent(record::getCustomerCostCentreName)
                .set(customerCostCentreNo).equalToWhenPresent(record::getCustomerCostCentreNo)
                .set(billable).equalToWhenPresent(record::getBillable)
                .set(customerCostCentreMandatory).equalToWhenPresent(record::getCustomerCostCentreMandatory)
                .set(username).equalToWhenPresent(record::getUsername)
                .set(description).equalToWhenPresent(record::getDescription)
                .set(createTimestamp).equalToWhenPresent(record::getCreateTimestamp)
                .set(syncTimestamp).equalToWhenPresent(record::getSyncTimestamp)
                .where(expenseId, isEqualTo(record::getExpenseId))
                .build()
                .execute();
    }
}